package com.cqc.jdk8.Jtime;

import org.junit.Test;

import java.time.Instant;

/**
 * @author cui
 * @date 2023/3/6 21:41
 **/
public class InstantTest {

    /**
     * 时间戳信息里同时包含了日期和时间，这和java.util.Date很像。实际上Instant类确实等同于 Java 8之前的Date类，
     * 你可以使用Date类和Instant类各自的转换方法互相转换，
     * 例如：Date.from(Instant) 将Instant转换成java.util.Date，
     * Date.toInstant()则是将Date类转换成Instant类
     */
    @Test
    public void f1() {
        Instant now = Instant.now();
        //2023-03-06T13:42:21.050Z
        System.out.println(now);
        long l1 = System.currentTimeMillis();
        long l2 = now.toEpochMilli();
        long epochSecond = now.getEpochSecond();
        // l1=1719676912698;
        // l2=1719676912660;
        // epochSecond=1719676912
        System.out.println("l1=" + l1 + ";l2=" + l2 + ";epochSecond=" + epochSecond);
    }
}
